#ifndef __WORKER_THREAD_POOL_H__
#define __WORKER_THREAD_POOL_H__

#include <vector>
#include "AcfDelegate.h"
#include "BlockingQueue.h"

namespace dsth {
class BaseThread;
class WorkerThreadPool {
public:
    typedef Acf::Delegate<void (void)> WorkerTask;
    WorkerThreadPool();
    ~WorkerThreadPool();
    void Run(int num);
    void Stop();
    void Put(const WorkerTask& wt);
    
private:
    // Can't invoke copy constructor or assignment operator
    WorkerThreadPool(const WorkerThreadPool&);
    void operator=(const WorkerThreadPool&);

    WorkerTask Take();
    void WorkFun(const char* threadName);
    BlockingQueue<WorkerTask> queue_;
    std::vector<BaseThread*> threads_;
    bool running_;
};

} // namespace
#endif // __WORKER_THREAD_POOL_H__
